package com.springcloud.feigndemo.Service

import com.springcloud.feigndemo.pojo.Word
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.core.io.Resource
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.multipart.MultipartFile

/*
    使用@FeignClient注解声明一个客户端.name属性在负载均衡是生效.url用来强制指定url.configuration指定该客户端的配置类,以提供个性化配置
 */
@FeignClient(name='feign-t',url = 'localhost')
interface FeignService {

    //声明一个Feign客户端方法和声明一个SpringMVC的控制器方法类似

   /*
        测试RequestInterceptor对FeignGet请求的拦截
        >. 如果开启压缩必须使用ResponseEntity<byte []>作为方法返回值,否则会乱码
        >. Feign不支持表单绑定功能,需要拦截请求并手动进行绑定
    */
    @GetMapping(value = 's')
    ResponseEntity<byte []> q(Word wd,@RequestParam('username') String username,@RequestParam('info') String info)


    /*
       测试上传文件.注意consumes属性,这会令SpringFormEncoder支持对MultipartFile编码
    */
    @PostMapping(value = 'upload',consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String file(@RequestPart('file') MultipartFile file)


    /*
        测试文件下载功能
     */
    @GetMapping(value = 'getImg',produces = MediaType.IMAGE_JPEG_VALUE)
    ResponseEntity<Resource> image()

}
